﻿Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient

Public Class frmNAP_DAUKY_TonNganHang
    Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents btnNew As System.Windows.Forms.Button
    Friend WithEvents btnSave As System.Windows.Forms.Button
    Friend WithEvents btnDelete1 As System.Windows.Forms.Button
    Friend WithEvents txtTienton As System.Windows.Forms.TextBox
    Friend WithEvents BtnClose As System.Windows.Forms.Button
    Friend WithEvents DataGridView1 As System.Windows.Forms.DataGridView
    Friend WithEvents TbldottonnganhangBindingSource As System.Windows.Forms.BindingSource
    Friend WithEvents DataSetNAP_DAUKY As ANLONG.DataSetNAP_DAUKY
    Friend WithEvents CBoNganHang As MTGCComboBox
    Friend WithEvents TxtNganHang As System.Windows.Forms.TextBox
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents RecycleIDDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents ma_nganhang As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TienDauKyDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TienThuDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TienChiDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TienTonDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TentaikhoanDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmNAP_DAUKY_TonNganHang))
        Dim DataGridViewCellStyle1 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Dim DataGridViewCellStyle2 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Dim DataGridViewCellStyle3 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Dim DataGridViewCellStyle4 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Me.btnSave = New System.Windows.Forms.Button
        Me.txtTienton = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.btnNew = New System.Windows.Forms.Button
        Me.btnDelete1 = New System.Windows.Forms.Button
        Me.BtnClose = New System.Windows.Forms.Button
        Me.DataGridView1 = New System.Windows.Forms.DataGridView
        Me.TbldottonnganhangBindingSource = New System.Windows.Forms.BindingSource(Me.components)
        Me.DataSetNAP_DAUKY = New ANLONG.DataSetNAP_DAUKY
        Me.CBoNganHang = New MTGCComboBox
        Me.TxtNganHang = New System.Windows.Forms.TextBox
        Me.Label9 = New System.Windows.Forms.Label
        Me.RecycleIDDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.ma_nganhang = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.TienDauKyDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.TienThuDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.TienChiDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.TienTonDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.TbldottonnganhangBindingSource, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.DataSetNAP_DAUKY, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'btnSave
        '
        Me.btnSave.BackColor = System.Drawing.Color.Transparent
        Me.btnSave.Image = CType(resources.GetObject("btnSave.Image"), System.Drawing.Image)
        Me.btnSave.Location = New System.Drawing.Point(165, 147)
        Me.btnSave.Name = "btnSave"
        Me.btnSave.Size = New System.Drawing.Size(96, 24)
        Me.btnSave.TabIndex = 3
        Me.btnSave.UseVisualStyleBackColor = False
        '
        'txtTienton
        '
        Me.txtTienton.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtTienton.Location = New System.Drawing.Point(158, 111)
        Me.txtTienton.MaxLength = 10
        Me.txtTienton.Name = "txtTienton"
        Me.txtTienton.Size = New System.Drawing.Size(144, 22)
        Me.txtTienton.TabIndex = 2
        Me.txtTienton.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Label2
        '
        Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.Location = New System.Drawing.Point(49, 111)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(103, 19)
        Me.Label2.TabIndex = 12
        Me.Label2.Text = "Tiền tồn cuối kỳ"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(69, 22)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(410, 24)
        Me.Label1.TabIndex = 11
        Me.Label1.Text = "NẠP ĐẦU KỲ TỒN TIỀN NGÂN HÀNG"
        '
        'btnNew
        '
        Me.btnNew.Image = CType(resources.GetObject("btnNew.Image"), System.Drawing.Image)
        Me.btnNew.Location = New System.Drawing.Point(60, 147)
        Me.btnNew.Name = "btnNew"
        Me.btnNew.Size = New System.Drawing.Size(96, 24)
        Me.btnNew.TabIndex = 4
        '
        'btnDelete1
        '
        Me.btnDelete1.Image = CType(resources.GetObject("btnDelete1.Image"), System.Drawing.Image)
        Me.btnDelete1.Location = New System.Drawing.Point(271, 147)
        Me.btnDelete1.Name = "btnDelete1"
        Me.btnDelete1.Size = New System.Drawing.Size(88, 24)
        Me.btnDelete1.TabIndex = 29
        '
        'BtnClose
        '
        Me.BtnClose.Image = CType(resources.GetObject("BtnClose.Image"), System.Drawing.Image)
        Me.BtnClose.Location = New System.Drawing.Point(368, 147)
        Me.BtnClose.Name = "BtnClose"
        Me.BtnClose.Size = New System.Drawing.Size(88, 24)
        Me.BtnClose.TabIndex = 30
        '
        'DataGridView1
        '
        Me.DataGridView1.AllowUserToAddRows = False
        Me.DataGridView1.AllowUserToDeleteRows = False
        Me.DataGridView1.AllowUserToResizeColumns = False
        Me.DataGridView1.AutoGenerateColumns = False
        Me.DataGridView1.BackgroundColor = System.Drawing.Color.LightBlue
        DataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter
        DataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control
        DataGridViewCellStyle1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        DataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText
        DataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight
        DataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText
        DataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.[True]
        Me.DataGridView1.ColumnHeadersDefaultCellStyle = DataGridViewCellStyle1
        Me.DataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
        Me.DataGridView1.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.RecycleIDDataGridViewTextBoxColumn, Me.ma_nganhang, Me.TienDauKyDataGridViewTextBoxColumn, Me.TienThuDataGridViewTextBoxColumn, Me.TienChiDataGridViewTextBoxColumn, Me.TienTonDataGridViewTextBoxColumn})
        Me.DataGridView1.DataSource = Me.TbldottonnganhangBindingSource
        Me.DataGridView1.Location = New System.Drawing.Point(35, 191)
        Me.DataGridView1.Name = "DataGridView1"
        Me.DataGridView1.ReadOnly = True
        Me.DataGridView1.Size = New System.Drawing.Size(447, 134)
        Me.DataGridView1.TabIndex = 46
        '
        'TbldottonnganhangBindingSource
        '
        Me.TbldottonnganhangBindingSource.DataMember = "tbl_dot_tonnganhang"
        Me.TbldottonnganhangBindingSource.DataSource = Me.DataSetNAP_DAUKY
        '
        'DataSetNAP_DAUKY
        '
        Me.DataSetNAP_DAUKY.DataSetName = "DataSetNAP_DAUKY"
        Me.DataSetNAP_DAUKY.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
        '
        'CBoNganHang
        '
        Me.CBoNganHang.ArrowBoxColor = System.Drawing.SystemColors.Control
        Me.CBoNganHang.ArrowColor = System.Drawing.Color.Black
        Me.CBoNganHang.BindedControl = Nothing
        Me.CBoNganHang.BorderStyle = MTGCComboBox.TipiBordi.Fixed3D
        Me.CBoNganHang.CharacterCasing = System.Windows.Forms.CharacterCasing.Normal
        Me.CBoNganHang.ColumnNum = 1
        Me.CBoNganHang.ColumnWidth = "121"
        Me.CBoNganHang.DisabledArrowBoxColor = System.Drawing.SystemColors.Control
        Me.CBoNganHang.DisabledArrowColor = System.Drawing.Color.LightGray
        Me.CBoNganHang.DisabledBackColor = System.Drawing.SystemColors.Control
        Me.CBoNganHang.DisabledBorderColor = System.Drawing.SystemColors.InactiveBorder
        Me.CBoNganHang.DisabledForeColor = System.Drawing.SystemColors.GrayText
        Me.CBoNganHang.DisplayMember = "Text"
        Me.CBoNganHang.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.CBoNganHang.DropDownBackColor = System.Drawing.Color.FromArgb(CType(CType(193, Byte), Integer), CType(CType(210, Byte), Integer), CType(CType(238, Byte), Integer))
        Me.CBoNganHang.DropDownForeColor = System.Drawing.Color.Black
        Me.CBoNganHang.DropDownStyle = MTGCComboBox.CustomDropDownStyle.DropDown
        Me.CBoNganHang.DropDownWidth = 141
        Me.CBoNganHang.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.CBoNganHang.GridLineColor = System.Drawing.Color.LightGray
        Me.CBoNganHang.GridLineHorizontal = False
        Me.CBoNganHang.GridLineVertical = False
        Me.CBoNganHang.LoadingType = MTGCComboBox.CaricamentoCombo.ComboBoxItem
        Me.CBoNganHang.Location = New System.Drawing.Point(158, 79)
        Me.CBoNganHang.ManagingFastMouseMoving = True
        Me.CBoNganHang.ManagingFastMouseMovingInterval = 30
        Me.CBoNganHang.Name = "CBoNganHang"
        Me.CBoNganHang.SelectedItem = Nothing
        Me.CBoNganHang.SelectedValue = Nothing
        Me.CBoNganHang.Size = New System.Drawing.Size(96, 23)
        Me.CBoNganHang.TabIndex = 1
        '
        'TxtNganHang
        '
        Me.TxtNganHang.BackColor = System.Drawing.SystemColors.Window
        Me.TxtNganHang.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TxtNganHang.Location = New System.Drawing.Point(255, 79)
        Me.TxtNganHang.MaxLength = 50
        Me.TxtNganHang.Name = "TxtNganHang"
        Me.TxtNganHang.ReadOnly = True
        Me.TxtNganHang.Size = New System.Drawing.Size(227, 22)
        Me.TxtNganHang.TabIndex = 103
        '
        'Label9
        '
        Me.Label9.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label9.Location = New System.Drawing.Point(52, 79)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(100, 19)
        Me.Label9.TabIndex = 102
        Me.Label9.Text = "Mã ngân hàng"
        Me.Label9.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'RecycleIDDataGridViewTextBoxColumn
        '
        Me.RecycleIDDataGridViewTextBoxColumn.DataPropertyName = "recycleID"
        DataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter
        DataGridViewCellStyle2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.RecycleIDDataGridViewTextBoxColumn.DefaultCellStyle = DataGridViewCellStyle2
        Me.RecycleIDDataGridViewTextBoxColumn.HeaderText = "Kỳ Quỹ"
        Me.RecycleIDDataGridViewTextBoxColumn.Name = "RecycleIDDataGridViewTextBoxColumn"
        Me.RecycleIDDataGridViewTextBoxColumn.ReadOnly = True
        '
        'ma_nganhang
        '
        Me.ma_nganhang.DataPropertyName = "ma_nganhang"
        DataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter
        DataGridViewCellStyle3.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ma_nganhang.DefaultCellStyle = DataGridViewCellStyle3
        Me.ma_nganhang.HeaderText = "Mã Ngân hàng"
        Me.ma_nganhang.Name = "ma_nganhang"
        Me.ma_nganhang.ReadOnly = True
        Me.ma_nganhang.Width = 120
        '
        'TienDauKyDataGridViewTextBoxColumn
        '
        Me.TienDauKyDataGridViewTextBoxColumn.DataPropertyName = "tienDauKy"
        Me.TienDauKyDataGridViewTextBoxColumn.HeaderText = "tienDauKy"
        Me.TienDauKyDataGridViewTextBoxColumn.Name = "TienDauKyDataGridViewTextBoxColumn"
        Me.TienDauKyDataGridViewTextBoxColumn.ReadOnly = True
        Me.TienDauKyDataGridViewTextBoxColumn.Visible = False
        '
        'TienThuDataGridViewTextBoxColumn
        '
        Me.TienThuDataGridViewTextBoxColumn.DataPropertyName = "tienThu"
        Me.TienThuDataGridViewTextBoxColumn.HeaderText = "tienThu"
        Me.TienThuDataGridViewTextBoxColumn.Name = "TienThuDataGridViewTextBoxColumn"
        Me.TienThuDataGridViewTextBoxColumn.ReadOnly = True
        Me.TienThuDataGridViewTextBoxColumn.Visible = False
        '
        'TienChiDataGridViewTextBoxColumn
        '
        Me.TienChiDataGridViewTextBoxColumn.DataPropertyName = "tienChi"
        Me.TienChiDataGridViewTextBoxColumn.HeaderText = "tienChi"
        Me.TienChiDataGridViewTextBoxColumn.Name = "TienChiDataGridViewTextBoxColumn"
        Me.TienChiDataGridViewTextBoxColumn.ReadOnly = True
        Me.TienChiDataGridViewTextBoxColumn.Visible = False
        '
        'TienTonDataGridViewTextBoxColumn
        '
        Me.TienTonDataGridViewTextBoxColumn.DataPropertyName = "tienTon"
        DataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight
        DataGridViewCellStyle4.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        DataGridViewCellStyle4.Format = "N0"
        Me.TienTonDataGridViewTextBoxColumn.DefaultCellStyle = DataGridViewCellStyle4
        Me.TienTonDataGridViewTextBoxColumn.HeaderText = "Tiền tồn"
        Me.TienTonDataGridViewTextBoxColumn.Name = "TienTonDataGridViewTextBoxColumn"
        Me.TienTonDataGridViewTextBoxColumn.ReadOnly = True
        Me.TienTonDataGridViewTextBoxColumn.Width = 150
        '
        'frmNAP_DAUKY_TonNganHang
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.LightBlue
        Me.ClientSize = New System.Drawing.Size(532, 353)
        Me.Controls.Add(Me.CBoNganHang)
        Me.Controls.Add(Me.TxtNganHang)
        Me.Controls.Add(Me.Label9)
        Me.Controls.Add(Me.DataGridView1)
        Me.Controls.Add(Me.BtnClose)
        Me.Controls.Add(Me.txtTienton)
        Me.Controls.Add(Me.btnDelete1)
        Me.Controls.Add(Me.btnNew)
        Me.Controls.Add(Me.btnSave)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Name = "frmNAP_DAUKY_TonNganHang"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "NAP DAU KY"
        CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.TbldottonnganhangBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.DataSetNAP_DAUKY, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region
    Private data1 As DataTable
    Private da As MySqlDataAdapter
    Dim myDT As New DataTable
    Dim strError As String = ""
    Dim myform As Form
    Dim sqlQuery As String = ""
    Sub SetclearData()
        txtTienton.Text = "0"
        TxtNganHang.Text = ""
        CBoNganHang.Text = ""

    End Sub
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        ' Kiểm tra có nhập liệu chưa ?
        If Me.checkInput() Then
            Dim txtMaTK = Me.CBoNganHang.Text.Trim
            sqlQuery = "SELECT recycleID FROM tbl_dot_tonnganhang WHERE  recycleID='" & globalVariale.NAPDAUKY & "' and ma_nganhang = '" & txtMaTK & "'"
            Dim existedMamon As Integer = moduleDatabaseConn.CheckRecordExisted(sqlQuery)
            If existedMamon = 1 Then ' Update record
                sqlQuery = "UPDATE tbl_dot_tonnganhang "
                sqlQuery += "SET "
                sqlQuery += " recycleID = '" & globalVariale.NAPDAUKY & "'"
                sqlQuery += ", tienDauky = 0"
                sqlQuery += ", tienthu = 0"
                sqlQuery += ", tienchi = 0"
                sqlQuery += ", tienton = '" & Replace(CDec(Me.txtTienton.Text.Trim), ",", ".") & "'"
                sqlQuery += ", ma_nganhang = '" & txtMaTK & "'"
                sqlQuery += " WHERE recycleID='" & globalVariale.NAPDAUKY & "'and ma_nganhang = '" & txtMaTK & "'"
                Dim updated As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                If updated = 1 Then
                    MessageBox.Show("Cập nhật thông tin thành công !")
                    sqlQuery = "SELECT * FROM tbl_dot_tonnganhang where recycleID='" & globalVariale.NAPDAUKY & "'"
                    Me.loadCDTK(sqlQuery)
                Else
                    MessageBox.Show("Cập nhật thông tin không thành công: " & globalVariale.sqlMsgError)
                End If

            Else
                If existedMamon = 0 Then ' Insert record
                    sqlQuery = "INSERT INTO tbl_dot_tonnganhang "
                    sqlQuery += "(recycleID,tienDauky, tienthu,tienchi,tienton,ma_nganhang) "
                    sqlQuery += "VALUES "
                    sqlQuery += "("
                    sqlQuery += "'" & globalVariale.NAPDAUKY & "', "
                    sqlQuery += "0, "
                    sqlQuery += "0, "
                    sqlQuery += "0, "
                    sqlQuery += "'" & Replace(CDec(Me.txtTienton.Text.Trim), ",", ".") & "',"
                    sqlQuery += "'" & Me.CBoNganHang.Text.Trim & "' "
                    sqlQuery += ")"
                    Dim inserted As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                    If inserted = 1 Then
                        MessageBox.Show("Thêm thông tin thành công !")
                        sqlQuery = "SELECT * FROM tbl_dot_tonnganhang where recycleID = '" & globalVariale.NAPDAUKY & "'"
                        Me.loadCDTK(sqlQuery)
                    Else
                        MessageBox.Show("Thêm thông tin không thành công: " & globalVariale.sqlMsgError)
                    End If
                Else ' SQLExeption: existedMaQuocGia = -1
                    MessageBox.Show("Lấy dữ liệu bị lỗi: " & globalVariale.sqlMsgError, "Lấy dữ liệu", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                End If
            End If
        End If



    End Sub
    Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
        SetclearData()
        txtTienton.Focus()
    End Sub
    Private Sub btnDelete1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete1.Click
        Dim txtMatk As String = Trim(Me.CBoNganHang.Text)
        If Me.TxtNganHang.Text = "" Then
            MessageBox.Show("Bạn chưa chọn Mã để xóa !")
        Else
            moduleConstants.MessageWarning = "Bạn có muốn xóa ? "

            If MessageBox.Show(moduleConstants.MessageWarning, globalVariale.msgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = MsgBoxResult.Yes Then
                Dim sqlQuery As String = "DELETE FROM tbl_dot_tonnganhang WHERE recycleID='" & globalVariale.NAPDAUKY & "' and ma_nganhang = '" & txtMatk & "' "
                Dim deleting As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                If deleting = 1 Then
                    MessageBox.Show("Xóa thông tin thành công !")
                    sqlQuery = "SELECT * FROM tbl_dot_tonnganhang where recycleID='" & globalVariale.NAPDAUKY & "'"
                    Me.loadCDTK(sqlQuery)
                    SetclearData()
                Else
                    MessageBox.Show("Xóa thông tin không thành công: " & globalVariale.sqlMsgError)
                End If
            End If
        End If
    End Sub
    Private Sub frmNAP_DAUKY_TonNganHang_load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        moduleUtils.setDinhDangVietNam()
        Me.loadCDTK("SELECT * FROM tbl_dot_tonnganhang where recycleID='" & globalVariale.NAPDAUKY & "'")
        Me.loadDanhSachNganHang()
        SetclearData()

    End Sub

    Private Sub BtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClose.Click
        Me.Close()
    End Sub
    Private Sub loadCDTK(ByVal sqlQuery As String)
        Me.DataGridView1.DataSource = moduleDatabaseConn.GetDataTable(sqlQuery)
    End Sub
    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Dim iRow As Integer = Me.DataGridView1.CurrentRow.Index
        Me.CBoNganHang.Text = Me.DataGridView1.Item(1, iRow).Value
        Me.txtTienton.Text = Format(CDbl(Me.DataGridView1.Item(5, iRow).Value), "N0")

    End Sub
    Private Sub loadDanhSachNganHang()
        Dim sqlQuery As String = ""
        sqlQuery = "SELECT ma_nganhang, ten_nganhang FROM tbl_nganhang ORDER BY ma_nganhang"
        data1 = moduleDatabaseConn.GetDataTable(sqlQuery)
        CBoNganHang.Items.Clear()
        CBoNganHang.LoadingType = MTGCComboBox.CaricamentoCombo.DataTable
        CBoNganHang.ColumnNum = 2
        CBoNganHang.ColumnWidth = "100;250"
        CBoNganHang.HighlightBorderColor = Color.Black
        CBoNganHang.GridLineHorizontal = True
        CBoNganHang.GridLineVertical = True
        CBoNganHang.ItemHeight = 17
        CBoNganHang.DropDownHeight = 300
        CBoNganHang.SourceDataTable = data1
        CBoNganHang.SelectedIndex = 0
    End Sub

    Private Sub CBoNganHang_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CBoNganHang.SelectedIndexChanged
        Try
            Me.TxtNganHang.Text = Me.CBoNganHang.SelectedItem.Col2
        Catch ex As Exception

        End Try
    End Sub
  
    Private Function checkInput() As Boolean
        If Me.CBoNganHang.Text = "" Then
            MessageBox.Show("Bạn phải chọn mã!")
            Me.CBoNganHang.Focus()
            Return False
            Exit Function
        End If
        If IsNumeric(Me.txtTienton.Text) = False Then
            MessageBox.Show("Bạn phải nhập số lượng là kiểu số !")
            Me.txtTienton.Focus()
            Return False
            Exit Function
        End If
       
        Return True
    End Function
End Class


